home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-06 / an105x.zip / LISTEN.C < prev   
C/C++ Source or Header  |  1991-04-10  |  2KB  |  98 lines

  1. /*****************************************************************************
  2. * LISTEN.C
  3. *
  4. * 91-04-05 Matt Hagen, Novell, Inc.
  5. *****************************************************************************/
  6.  
  7. #include "ipx.h"
  8.  
  9. #define WELL_KNOWN_SOCKET 0x2361        /* backwards */
  10. #define RX_DATA_SIZE 50
  11. #define TX_DATA_SIZE 50
  12. #define STATUS_RUN 0
  13. #define STATUS_UNLOAD 1
  14.  
  15. extern void SignalRoutine(
  16.     void);
  17.  
  18. SESSION *s;
  19. BYTE statusFlag=STATUS_RUN;
  20. int exitThread=NULL;
  21.  
  22. /*****************************************************************************
  23. * main
  24. *****************************************************************************/
  25.  
  26. main(
  27.     int argc,
  28.     char *argv[])
  29. {
  30.     IPX_ECB *rx;
  31.     IPX_ECB *rxList;
  32.  
  33.     signal(SIGTERM,SignalRoutine);
  34.  
  35.     s=AllocateIPXResources(WELL_KNOWN_SOCKET,NULL,8,RX_DATA_SIZE,3,TX_DATA_SIZE);
  36.     if(s==NULL)
  37.     {
  38.         ConsolePrintf("  Error allocating session.\n");
  39.         statusFlag=STATUS_UNLOAD;
  40.         goto exit0;
  41.     }
  42.  
  43.     while(TRUE)
  44.     {
  45.         WaitOnLocalSemaphore(s->semaphore);
  46.  
  47.         if(statusFlag==STATUS_UNLOAD)
  48.             goto exit1;
  49.  
  50.         rx=IpxGetAndClearQ(&s->rxHead);
  51.         rxList=rx->prev;
  52.         rx->prev=NULL;
  53.  
  54.         while(rxList!=NULL)
  55.         {
  56.             rx=rxList;
  57.             rxList=rx->prev;
  58.  
  59.             /* process rx */
  60.  
  61.             ConsolePrintf(" ***  ");
  62.  
  63.             IpxReceive(NULL,rx);
  64.  
  65.             if(rxList!=NULL)
  66.                 WaitOnLocalSemaphore(s->semaphore);
  67.  
  68.             ThreadSwitch();
  69.  
  70.             if(statusFlag==STATUS_UNLOAD)
  71.                 goto exit1;
  72.         }
  73.     }
  74.  
  75. exit1:;
  76.     DeallocateIPXResources(s);
  77.  
  78. exit0:;
  79.     if(exitThread!=NULL)
  80.         ResumeThread(exitThread);
  81. }
  82.  
  83. /*****************************************************************************
  84. * SignalRoutine
  85. *****************************************************************************/
  86.  
  87. void SignalRoutine(
  88.     void)
  89. {
  90.     exitThread=GetThreadID();
  91.     statusFlag=STATUS_UNLOAD;
  92.     SignalLocalSemaphore(s->semaphore);
  93.     SuspendThread(exitThread);
  94. }
  95.  
  96. /****************************************************************************/
  97. /****************************************************************************/
  98.